<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>setTimeout clearTimeout</title>
</head>
<body>

    <input type="button" value="开始计时！" onClick="timedCount()">
    <input type="text" id="txt">
    <input type="button" value="停止计时！" onClick="stopCount()">

    <script type="text/javascript">
        var c = 0;
        var t;

        function timedCount() {
            document.getElementById('txt').value = c;
            c = c + 1;
            t = setTimeout("timedCount()", 1000);
        }

        function stopCount() {
            clearTimeout(t);
        }
    </script>

</body>
</html>